<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    var breakPalindrome = function (arr) {
      let n = arr.length >> 1
      for (let i = 0; i < n; i++) {
        if (arr[i] !== 'a') return arr.replace(/[^a]/, 'a')
      }
      if (arr.length > 1) return arr.slice(0, -1) + 'b'
      return ''
    };
    console.log(breakPalindrome("abccba"));
  </script>
</body>

</html>